/* 
 * Copyright (C) 2012 UTSChedule
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package utsc.apps.utschedule.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

/**
 * A simple custom ui widget that can allow user to select a color from a color picker.
 * @author Wenbin
 *
 */
public class ColorCellView extends View {

	private int _currentColor=Color.WHITE;
	private int _size=50;
	
	public ColorCellView(Context context) {
		super(context);
		setupView(context);
	}

	public ColorCellView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		setupView(context);
	}

	public ColorCellView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupView(context);
	}
	
	public void set_currentColor(int _currentColor) {
		this._currentColor = _currentColor;
		setBackgroundColor(_currentColor);
		invalidate();
	}
	
	private void setupView(Context context) {
		setBackgroundColor(_currentColor);
		_size=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _size, getResources().getDisplayMetrics());
	}
	
	public int get_currentColor() {
		return _currentColor;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		
		setMeasuredDimension(resolveSize(_size, widthMeasureSpec), resolveSize(_size, heightMeasureSpec));
	}
	
}
